home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / shared / movingav / movingav.m < prev    next >
Text File  |  1993-07-18  |  785b  |  43 lines

  1. (* Copyright 1988,1990 Wolfram Research, Inc. *)
  2.  
  3. (*:Version: Mathematica 2.0 *)
  4.  
  5. (*:Name: Statistics`MovingAverage` *)
  6.  
  7. (*:Author:
  8.         Wolfram Research, Inc. 
  9. *)
  10.  
  11. (*:Keywords: moving average *)
  12.  
  13.  
  14. (*:Requirements: none. *)
  15.  
  16. (*:Warnings: none. *)
  17.  
  18. BeginPackage["Statistics`MovingAverage`"]
  19.  
  20. MovingAverage::usage=
  21. "MovingAverage[list,n] returns a list of the n-th moving averages of list."
  22.  
  23. Begin["`Private`"]
  24.  
  25. Mean[list_List] := (Plus @@ list)/Length[list]
  26.  
  27. MovingAverage[list:{{_,_}..}, n_Integer] :=
  28. Block[{list1, list2},
  29.     {list1, list2} = Transpose[list];
  30.     Table[
  31.         {list1[[i+Floor[n/2]]], 
  32.         Mean[Take[list2,{i, i+n}]]}, 
  33.             {i,1, Length[list]-n}]
  34.     ]
  35.  
  36. MovingAverage[list_List, n_Integer] :=
  37.     Table[Mean[Take[list, {i, i+n}]], 
  38.         {i,1, Length[list]-n}]
  39.     
  40.     End[ ]
  41.  
  42.     EndPackage[ ]
  43.